package com.kurumi.medical.service.impl;

import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kurumi.medical.datasource.TargetDataSource;
import com.kurumi.medical.mapper.CitizensInfoMapper;
import com.kurumi.medical.mapper.ExportDataMapper;
import com.kurumi.medical.mapper.FirstLevelMedicalMapper;
import com.kurumi.medical.mapper.HospitalizationNoteMapper;
import com.kurumi.medical.pojo.CitizensInfo;
import com.kurumi.medical.pojo.FirstLevelMedical;
import com.kurumi.medical.pojo.HospitalizationChangeOffice;
import com.kurumi.medical.pojo.HospitalizationChangeOfficeInfo;
import com.kurumi.medical.pojo.HospitalizationCost;
import com.kurumi.medical.pojo.HospitalizationCureInfo;
import com.kurumi.medical.pojo.HospitalizationDiagnosis;
import com.kurumi.medical.pojo.HospitalizationDiagnosisInfo;
import com.kurumi.medical.pojo.HospitalizationNote;
import com.kurumi.medical.pojo.HospitalizationNoteBasic;
import com.kurumi.medical.pojo.HospitalizationNurseRecordInfo;
import com.kurumi.medical.pojo.HospitalizationOperation;
import com.kurumi.medical.pojo.HospitalizationOperationInfo;
import com.kurumi.medical.pojo.HospitalizationPressureSoreInfo;
import com.kurumi.medical.service.ExportDataService;
import com.kurumi.medical.service.HospNoteBasicJsonService;
import com.kurumi.medical.util.CreateFileUtil;
import com.kurumi.medical.util.DateUtil;
import com.kurumi.medical.util.JsonUtils;
import com.kurumi.medical.util.OracleDataTable;
import com.kurumi.medical.util.Result;
import com.kurumi.medical.util.StringUtil;

@Service
public class ExportDataServiceImpl implements ExportDataService {
	
	@Autowired
	private ExportDataMapper exportDataMapper;
	
	@Override
	public List<Map<String, Object>> getMarriagesByOracle() {
		
		return exportDataMapper.getMarriagesByOracle();
	}

	@Override
	@Transactional
	@TargetDataSource(name="ds1")
	public boolean insertMarrigeBatch(List<Map<String, Object>> list) {
		boolean result = false;
		int count = exportDataMapper.insertMarrigeBatch(list);
		
		if(count>0){
			result =true;
		}
		return result;
	}

	@Override
	public List<Map<String, Object>> getSexByOracle() {
		return exportDataMapper.getSexByOracle();
	}

	@Override
	public List<Map<String, Object>> getIdentityByOracle() {
		return exportDataMapper.getIdentityByOracle();
	}

	@Override
	public List<Map<String, Object>> getOutpByOracle() {
		return exportDataMapper.getOutpByOracle();
	}

	@Override
	public List<Map<String, Object>> getInternalOutByOracle() {
		return exportDataMapper.getInternalOutByOracle();
	}

	@Override
	public List<Map<String, Object>> getOfficeByOracle() {
		return exportDataMapper.getOfficeByOracle();
	}

	@Override
	public List<Map<String, Object>> getClinicAttrByOracle() {
		return exportDataMapper.getClinicAttrByOracle();
	}

	@Override
	@Transactional
	@TargetDataSource(name="ds1")
	public boolean insertSexBatch(List<Map<String, Object>> list) {
		boolean result = false;
		int count = exportDataMapper.insertSexBatch(list);
		
		if(count>0){
			result =true;
		}
		return result;
	}

	@Override
	@Transactional
	@TargetDataSource(name="ds1")
	public boolean insertIdentityInfoBatch(List<Map<String, Object>> list) {
		boolean result = false;
		int count = exportDataMapper.insertIdentityInfoBatch(list);
		
		if(count>0){
			result =true;
		}
		return result;
	}

	@Override
	@Transactional
	@TargetDataSource(name="ds1")
	public boolean insertOfficeOutpBatch(List<Map<String, Object>> list) {
		boolean result = false;
		int count = exportDataMapper.insertOfficeOutpBatch(list);
		
		if(count>0){
			result =true;
		}
		return result;
	}

	@Override
	@Transactional
	@TargetDataSource(name="ds1")
	public boolean insertInternalOutBatch(List<Map<String, Object>> list) {
		boolean result = false;
		int count = exportDataMapper.insertInternalOutBatch(list);
		
		if(count>0){
			result =true;
		}
		return result;
	}

	@Override
	@Transactional
	@TargetDataSource(name="ds1")
	public boolean insertClinicAttrBatch(List<Map<String, Object>> list) {
		boolean result = false;
		int count = exportDataMapper.insertClinicAttrBatch(list);
		
		if(count>0){
			result =true;
		}
		return result;
	}

	@Override
	@Transactional
	@TargetDataSource(name="ds1")
	public boolean insertOfficeBatch(List<Map<String, Object>> list) {
		boolean result = false;
		int count = exportDataMapper.insertOfficeBatch(list);
		
		if(count>0){
			result =true;
		}
		return result;
	}

	@Override
	public List<Map<String, Object>> getNationByOracle() {
		return exportDataMapper.getNationByOracle();
	}

	@Override
	public List<Map<String, Object>> getBloodTypeByOracle() {
		return exportDataMapper.getBloodTypeByOracle();
	}

	@Override
	public List<Map<String, Object>> getAreaByOracle() {
		return exportDataMapper.getAreaByOracle();
	}

	@Override
	public List<Map<String, Object>> getProfessionByOracle() {
		return exportDataMapper.getProfessionByOracle();
	}

	@Override
	public List<Map<String, Object>> getRelationShipByOracle() {
		return exportDataMapper.getRelationShipByOracle();
	}

	@Override
	public List<Map<String, Object>> getInHospTypeByOracle() {
		return exportDataMapper.getInHospTypeByOracle();
	}

	@Override
	public List<Map<String, Object>> getInHospStatusByOracle() {
		return exportDataMapper.getInHospStatusByOracle();
	}

	@Override
	public List<Map<String, Object>> getOutHospTypeByOracle() {
		return exportDataMapper.getOutHospTypeByOracle();
	}

	@Override
	@TargetDataSource(name="ds1")
	@Transactional
	public boolean insertNationBatch(List<Map<String, Object>> list) {
		boolean result = false;
		
		int count = exportDataMapper.insertNationBatch(list);
		if(count>0){
			result = true;
		}
		
		return result;
	}

	@Override
	@TargetDataSource(name="ds1")
	@Transactional
	public boolean insertBloodTypeBatch(List<Map<String, Object>> list) {
		boolean result = false;
		
		int count = exportDataMapper.insertBloodTypeBatch(list);
		if(count>0){
			result = true;
		}
		
		return result;
	}

	@Override
	@TargetDataSource(name="ds1")
	@Transactional
	public boolean insertCountryBatch(List<Map<String, Object>> list) {
		
		boolean result = false;
		
		int count = exportDataMapper.insertCountryBatch(list);
		if(count>0){
			result = true;
		}
		
		return result;
	}

	@Override
	@TargetDataSource(name="ds1")
	@Transactional
	public boolean insertAreaBatch(List<Map<String, Object>> list) {
		boolean result = false;
		
		int count = exportDataMapper.insertAreaBatch(list);
		if(count>0){
			result = true;
		}
		
		return result;
	}

	@Override
	@TargetDataSource(name="ds1")
	@Transactional
	public boolean insertProfessionBatch(List<Map<String, Object>> list) {
		boolean result = false;
		
		int count = exportDataMapper.insertProfessionBatch(list);
		if(count>0){
			result = true;
		}
		
		return result;
	}

	@Override
	@TargetDataSource(name="ds1")
	@Transactional
	public boolean insertRelationBatch(List<Map<String, Object>> list) {
		boolean result = false;
		
		int count = exportDataMapper.insertRelationBatch(list);
		if(count>0){
			result = true;
		}
		
		return result;
	}

	@Override
	@TargetDataSource(name="ds1")
	@Transactional
	public boolean insertInHosTypeBatch(List<Map<String, Object>> list) {
		boolean result = false;
		
		int count = exportDataMapper.insertInHosTypeBatch(list);
		if(count>0){
			result = true;
		}
		
		return result;
	}

	@Override
	@TargetDataSource(name="ds1")
	@Transactional
	public boolean insertInHosStatusBatch(List<Map<String, Object>> list) {
		boolean result = false;
		
		int count = exportDataMapper.insertInHosStatusBatch(list);
		if(count>0){
			result = true;
		}
		
		return result;
	}

	@Override
	@TargetDataSource(name="ds1")
	@Transactional
	public boolean insertOutHosTypeBatch(List<Map<String, Object>> list) {
		boolean result = false;
		
		int count = exportDataMapper.insertOutHosTypeBatch(list);
		if(count>0){
			result = true;
		}
		
		return result;
	}

	@Override
	public List<Map<String, Object>> getCountryByOracle() {
		return exportDataMapper.getCountryByOracle();
	}

	@Override
	public List<Map<String, Object>> getDataByOracle(Map<String, Object> map) {
		return exportDataMapper.getDataByOracle(map);
	}

	@Override
	@TargetDataSource(name="ds1")
	@Transactional
	public List<Result> inserDataTable(List<Map<String, Object>> map,List<Map<String,Object>> otherList){
		
		List<Result> list = new ArrayList<>();
		
		if(map!=null && !map.isEmpty()){
			for(Map<String,Object> dataMap :map){
				List<Map<String, Object>> datas = (List<Map<String, Object>>)dataMap.get("datas");
				/*for(Map<String, Object> data : datas){
					for (String key : data.keySet()) {
						Object value = data.get(key);
						
						
						if(value instanceof String){
							String dealValue = null;
							try {
								dealValue = new String(((String)value).getBytes("ISO8859-1"),"gbk");
							} catch (UnsupportedEncodingException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
							data.put(key, dealValue);
						}else if(value instanceof BigDecimal){
							
							data.put(key, ((BigDecimal)value).intValue());
						}else{
							String dealValue = null;
							try {
								dealValue = new String(((String)value).getBytes("ISO8859-1"),"gbk");
							} catch (UnsupportedEncodingException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
							data.put(key, dealValue);
						}
						
						
						
					}
				}*/
				
				int count = exportDataMapper.inserDataTable(dataMap);
				if(count>0){
					list.add(new Result(true,"导入成功",dataMap.get("oracleTableName")));
				}else{
					list.add(new Result(true,"导入失败",dataMap.get("oracleTableName")));
				}
			/*catch(Exception e){
				list.add(new Result(true,"导入失败",dataMap.get("oracleTableName")));
				System.out.println(e.getMessage());
			}*/
				
			}
		}
		
		if(otherList!=null && !otherList.isEmpty()){
			int count = 0;
			for(Map<String,Object> otherDataMap :otherList){
				
				List<Map<String, Object>> datas = (List<Map<String, Object>>)otherDataMap.get("datas");
				/*for(Map<String, Object> data : datas){
						for (String key : data.keySet()) {
							Object value = data.get(key);
							
							
							if(value instanceof String){
								String dealValue = null;
								try {
									dealValue = new String(((String)value).getBytes("ISO8859-1"),"gbk");
								} catch (UnsupportedEncodingException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}
								data.put(key, dealValue);
							}else if(value instanceof BigDecimal){
								
								data.put(key, ((BigDecimal)value).intValue());
							}else{
								String dealValue = null;
								try {
									dealValue = new String(((String)value).getBytes("ISO8859-1"),"gbk");
								} catch (UnsupportedEncodingException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}
								data.put(key, dealValue);
							}
						}
					}*/
					if(OracleDataTable.IDENTITY.equals(otherDataMap.get("oracleTableName"))){
						 count = exportDataMapper.insertIdentityInfoBatch((List<Map<String, Object>>)otherDataMap.get("datas"));
					}else if(OracleDataTable.DEPTCLINICATTR.equals(otherDataMap.get("oracleTableName"))){
						count = exportDataMapper.insertClinicAttrBatch((List<Map<String, Object>>)otherDataMap.get("datas"));
					}else if(OracleDataTable.DEPTISATTR.equals(otherDataMap.get("oracleTableName"))){
						count = exportDataMapper.insertInternalOutBatch((List<Map<String, Object>>)otherDataMap.get("datas"));
					}else if(OracleDataTable.DEPTOIATTR.equals(otherDataMap.get("oracleTableName"))){
						count = exportDataMapper.insertOfficeOutpBatch((List<Map<String, Object>>)otherDataMap.get("datas"));
					}else if(OracleDataTable.DEPT.equals(otherDataMap.get("oracleTableName"))){
						count = exportDataMapper.insertOfficeBatch(datas);
					}else if(OracleDataTable.ILLNESSSTATE.equals(otherDataMap.get("oracleTableName"))){
						count = exportDataMapper.insertInHosStatusBatch(datas);
					}else if(OracleDataTable.TITLE.equals(otherDataMap.get("oracleTableName"))){
						
						count = exportDataMapper.insertMedicalProfessionalTitlesBatch(datas);
					}else if(OracleDataTable.JOB_CLASS.equals(otherDataMap.get("oracleTableName"))){
						
						count = exportDataMapper.insertMedicalProfessionalsBatch(datas);
					}else if(OracleDataTable.CHARGE_TYPE.equals(otherDataMap.get("oracleTableName"))){
						
						count = exportDataMapper.insertMedicalPaymentTypesBatch(datas);
					}else if(OracleDataTable.DIAGNOSIS.equals(otherDataMap.get("oracleTableName"))){
						
						count = exportDataMapper.insertDiseaseBatch(datas);
					}else if(OracleDataTable.OPERATION.equals(otherDataMap.get("oracleTableName"))){
						
						count = exportDataMapper.insertOperationBatch(datas);
					}
					else if(OracleDataTable.STAFF.equals(otherDataMap.get("oracleTableName"))){
						
						count = insetMedicalWorks(datas);
					}
					
					if(count>0){
						list.add(new Result(true,"导入成功",otherDataMap.get("oracleTableName")));
					}else{
						list.add(new Result(true,"导入失败",otherDataMap.get("oracleTableName")));
					}
			}

		}
		
		return list;
	}

	@TargetDataSource(name="ds1")
	@Transactional
	private int insetMedicalWorks(List<Map<String, Object>> datas){
		for (Map<String, Object> map : datas) {
			String deptCode = map.get("DEPTCODE")!=null ? map.get("DEPTCODE").toString():null;
			String jobName = map.get("JOBNAME")!=null ? map.get("JOBNAME").toString():null;
			String titleName = map.get("TITILNAME")!=null ? map.get("TITILNAME").toString():null;
			List<Map<String, Object>> deptIds = new ArrayList<Map<String, Object>>();
			Integer deptId = null;
			if(deptCode!=null){
				deptIds = exportDataMapper.getOfficesByOfficeCode(deptCode);
				if(!deptIds.isEmpty()){
					deptId = Integer.parseInt(deptIds.get(0).get("id").toString());
				}
			}
			map.put("DEPTID", deptId);
			List<Map<String, Object>> jobIds = new ArrayList<Map<String, Object>>();
			Integer jobId = null;
			if(jobName != null){
				jobIds = exportDataMapper.getMedicalProfessionIdsByName(jobName);
				if(!jobIds.isEmpty()){
					jobId = Integer.parseInt(jobIds.get(0).get("id").toString());
				}
			}
			map.put("JOBID", jobId);
			List<Map<String, Object>> titleIds = new ArrayList<Map<String, Object>>();
			Integer titleId = null;
			if(titleName  != null){
				titleIds = exportDataMapper.getMedicalProfessionIdsByName(titleName);
				if(!titleIds.isEmpty()){
					titleId = Integer.parseInt(titleIds.get(0).get("id").toString());
				}
			}
			map.put("TITILID", titleId);
			
		}
		return exportDataMapper.insertMedicalWorkBatch(datas);
	}
	
	@Override
	public List<Map<String, Object>> getTitileByOracle() {
		// TODO Auto-generated method stub
		return exportDataMapper.getTitileByOracle();
	}

	@Override
	public List<Map<String, Object>> getJobClassByOracle() {
		// TODO Auto-generated method stub
		return exportDataMapper.getJobClassByOracle();
	}

	@Override
	public List<Map<String, Object>> getChargeTypeByOracle() {
		// TODO Auto-generated method stub
		return exportDataMapper.getChargeTypeByOracle();
	}

	@Override
	public List<Map<String, Object>> getDiagnosisByOracle() {
		// TODO Auto-generated method stub
		return exportDataMapper.getDiagnosisByOracle();
	}

	@Override
	public List<Map<String, Object>> getOperationsByOracle() {
		// TODO Auto-generated method stub
		return exportDataMapper.getOperationsByOracle();
	}

	@Override
	public List<Map<String, Object>> getStaffsByOracle() {
		// TODO Auto-generated method stub
		return exportDataMapper.getStaffsByOracle();
	}

	@Override
	public List<Map<String, Object>> getOracleMedicalHospitalRecord(){
		List<Map<String, Object>> medicalRecords = exportDataMapper.getMedicalHospitalRecordByOracle();
		List<Map<String, Object>> dates = new ArrayList<Map<String,Object>>();
		for(Map<String, Object> medicalRecord : medicalRecords){
			for (String key : medicalRecord.keySet()) {
				Object value = medicalRecord.get(key);
			
			
				if(value instanceof String){
					String dealValue = null;
					try {
						dealValue = new String(((String)value).getBytes("ISO8859-1"),"gbk");
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					medicalRecord.put(key, dealValue);
				}
			}
			Map<String, Object> data = new HashMap<String, Object>();
			data.put("medicalRecord", medicalRecord);
			String mrId = medicalRecord.get("MRID")!=null ? medicalRecord.get("MRID").toString():null;
			BigDecimal inHospitalNumber = medicalRecord.get("INHOSPITALNUMBER")!=null ? (BigDecimal)medicalRecord.get("INHOSPITALNUMBER"):null;
			List<Map<String, Object>> diagnosisRecords = exportDataMapper.getOracleDiagnosisOfByPatientIdAndVisitId(mrId, ""+inHospitalNumber.intValue());
			for(Map<String, Object> diagnosisRecord : diagnosisRecords){
				for (String key : diagnosisRecord.keySet()) {
					Object value = diagnosisRecord.get(key);
				
				
					if(value instanceof String){
						String dealValue = null;
						try {
							dealValue = new String(((String)value).getBytes("ISO8859-1"),"gbk");
						} catch (UnsupportedEncodingException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						diagnosisRecord.put(key, dealValue);
					}
				}
			}
			data.put("diagnosisRecords", diagnosisRecords);
			
			List<Map<String, Object>> operationRecords = exportDataMapper.getOracleOperationOfByPatientIdAndVisitId(mrId, ""+inHospitalNumber.intValue());
			for(Map<String, Object> operationRecord : operationRecords){
				for (String key : operationRecord.keySet()) {
					Object value = operationRecord.get(key);
				
				
					if(value instanceof String){
						String dealValue = null;
						try {
							dealValue = new String(((String)value).getBytes("ISO8859-1"),"gbk");
						} catch (UnsupportedEncodingException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						operationRecord.put(key, dealValue);
					}
				}
			}
			data.put("operationRecords", operationRecords);
			
			List<Map<String, Object>> changeOfficeRecords = exportDataMapper.getOracleTransferByPatientIdAndVisitId(mrId, ""+inHospitalNumber.intValue());
			
			for(Map<String, Object> changeOfficeRecord : changeOfficeRecords){
				for (String key : changeOfficeRecord.keySet()) {
					Object value = changeOfficeRecord.get(key);
				
				
					if(value instanceof String){
						String dealValue = null;
						try {
							dealValue = new String(((String)value).getBytes("ISO8859-1"),"gbk");
						} catch (UnsupportedEncodingException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						changeOfficeRecord.put(key, dealValue);
					}
				}
			}
			data.put("changeOfficeRecords", changeOfficeRecords);
			List<Map<String, Object>> diagComparingRecords = exportDataMapper.getOracleDiagComparingByPatientIdAndVisitId(mrId, ""+inHospitalNumber.intValue());
			for(Map<String, Object> diagComparingRecord : diagComparingRecords){
				for (String key : diagComparingRecord.keySet()) {
					Object value = diagComparingRecord.get(key);
				
				
					if(value instanceof String){
						String dealValue = null;
						try {
							dealValue = new String(((String)value).getBytes("ISO8859-1"),"gbk");
						} catch (UnsupportedEncodingException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						diagComparingRecord.put(key, dealValue);
					}
				}
			}
			data.put("diagComparingRecords", diagComparingRecords);
			dates.add(data);
		}
		
		
		return dates;
	}
	
	@Autowired
	private CitizensInfoMapper patientMapper;
	
	@Autowired
	private FirstLevelMedicalMapper firstLevelMedicalMapper;
	
	@Autowired
	private HospitalizationNoteMapper hospitalizationNoteMapper;
	
	@Autowired
	private HospNoteBasicJsonService hospNoteBasicJsonService;
	
///*	public int insertMysqlMedicalHospitalRecord(Map<String, Object> data){*/
//		Map<String, Object> map = (Map<String, Object>)data.get("medicalRecord");
//		CitizensInfo patient = new CitizensInfo();
//		patient.setGuid(StringUtil.getId());
//		String name = map.get("PATIENTNAME")!=null ? map.get("PATIENTNAME").toString():null;
//		patient.setName(name);
//		String sexName = map.get("SEXNAME")!=null ? map.get("SEXNAME").toString():null;
//		Integer sexId = null;
//		if(sexName != null){
//			List<Map<String, Object>> sexIds = new ArrayList<Map<String, Object>>();
//			
//			sexIds = exportDataMapper.getSexIdsByName(sexName);
//			if(!sexIds.isEmpty()){
//				sexId = Integer.parseInt(sexIds.get(0).get("id").toString());
//			}
//		}
//		patient.setSexId(sexId);
//		String birthdayStr =  map.get("BIRTHDAY")!=null ? map.get("BIRTHDAY").toString():null;
//		Date birthday = null;
//		if(birthdayStr != null){
//			try {
//				birthday = DateUtil.dateParse(birthdayStr);
//			} catch (ParseException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//		}
//		patient.setBirthday(birthday);
//		String idCard = map.get("IDCARD")!=null ? map.get("IDCARD").toString():null;
//		patient.setIdType(1);
//		patient.setIdNumber(idCard);
//		patient.setStatus(1);
//		patient.setCreateDate(new Date());
//		patient.setUpdateDate(new Date());
//		
//		FirstLevelMedical firstLevelMedical = new FirstLevelMedical();
//		firstLevelMedical.setCitizensGuid(patient.getGuid());
//		firstLevelMedical.setHospitalId(1);
//		firstLevelMedical.setGuid(StringUtil.getId());
//		firstLevelMedical.setTreatmentSignId(1);
//		firstLevelMedical.setTreatmentTypeId(1);
//		firstLevelMedical.setCreateDate(new Date());
//		firstLevelMedical.setUpdateDate(new Date());
//		firstLevelMedical.setStatus(1);
//		
//		HospitalizationNote note = new HospitalizationNote();
//		note.setFirstLevelMedicalGuid(firstLevelMedical.getGuid());
//		String inHospitalDateStr = map.get("INHOSPITALDATE")!=null ? map.get("INHOSPITALDATE").toString():null;
//		Date inHospitalDate = null;
//		if(inHospitalDateStr != null){
//			try {
//				inHospitalDate = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,inHospitalDateStr);
//			} catch (ParseException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//		}
//		note.setInHospitalDate(inHospitalDate);
//		
//		
//		String outHospitalDateStr = map.get("OUTHOSPITALDATE")!=null ? map.get("OUTHOSPITALDATE").toString():null;
//		Date outHospitalDate = null;
//		if(outHospitalDateStr != null){
//			try {
//				outHospitalDate = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,outHospitalDateStr);
//			} catch (ParseException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//		}
//		note.setOutHospitalDate(outHospitalDate);
//		String inDeptCode = map.get("INDEPTCODE")!=null ? map.get("INDEPTCODE").toString():null;
//		List<Map<String, Object>> inDepts = new ArrayList<Map<String, Object>>();
//		Integer inDeptId = null;
//		String inDeptName = null;
//		if(inDeptCode!=null){
//			inDepts = exportDataMapper.getOfficesByOfficeCode(inDeptCode);
//			if(!inDepts.isEmpty()){
//				inDeptId = Integer.parseInt(inDepts.get(0).get("id").toString());
//				inDeptName = inDepts.get(0).get("name").toString();
//			}
//		}
//		note.setInDeptId(inDeptId);
//		
//		String outDeptCode = map.get("OUTDEPTCODE")!=null ? map.get("OUTDEPTCODE").toString():null;
//		List<Map<String, Object>> outDepts = new ArrayList<Map<String, Object>>();
//		Integer outDeptId = null;
//		String outDeptName = null;
//		if(outDeptCode!=null){
//			outDepts = exportDataMapper.getOfficesByOfficeCode(outDeptCode);
//			if(!outDepts.isEmpty()){
//				outDeptId = Integer.parseInt(outDepts.get(0).get("id").toString());
//				outDeptName = outDepts.get(0).get("name").toString();
//			}
//		}
//		note.setOutDeptId(outDeptId);
//		
//		String mrId = map.get("MRID")!=null ? map.get("MRID").toString():null;
//		String onlyId = map.get("ONLYID")!=null ? map.get("ONLYID").toString():null;
//		String visitNumber=(String) map.get("VISITNUMBER");
//		note.setMrId(mrId);
//		note.setOnlyId(onlyId);
//		note.setVisitNumber(Integer.valueOf(visitNumber));
//		int count = hospitalizationNoteMapper.getHospitalizationNoteCountByMrIdAndOnlyId(mrId,Integer.valueOf(visitNumber));
//		if(count > 0){
//			return 1;
//		}
//		patientMapper.insert(patient);
//		firstLevelMedicalMapper.insert(firstLevelMedical);
//		String outHospitalTypeCode = map.get("OUTHOSPITALTYPECODE")!=null ? map.get("OUTHOSPITALTYPECODE").toString():null;
//		List<Map<String, Object>> outHospitalTypes = new ArrayList<Map<String, Object>>();
//		Integer outHospitalTypeId = null;
//		String outHospitalTypeName = null;
//		if(outHospitalTypeCode!=null){
//			outHospitalTypes = exportDataMapper.getOutHospitalTypeByCode(outHospitalTypeCode);
//			if(!outHospitalTypes.isEmpty()){
//				outHospitalTypeId = Integer.parseInt(outHospitalTypes.get(0).get("id").toString());
//				outHospitalTypeName = outHospitalTypes.get(0).get("name").toString();
//			}
//		}
//		note.setOutHospitalTypeId(outHospitalTypeId);
//		hospitalizationNoteMapper.insert(note);
//		
//		HospitalizationNoteBasic basic = new HospitalizationNoteBasic();
//		basic.setFirstGuid(firstLevelMedical.getGuid());
//		basic.setOnlyId(onlyId);
//		basic.setMrId(mrId);
//		basic.setHospitalId(1);
//		basic.setHospitalName("XX医院");
//		BigDecimal inHospitalNumber = map.get("INHOSPITALNUMBER")!=null ? (BigDecimal)map.get("INHOSPITALNUMBER"):null;
//		if(inHospitalNumber !=null){
//			basic.setInHospitalNumber(inHospitalNumber.intValue());
//		}
//		basic.setName(name);
//		basic.setIdentityDocumentTypeId(1);
//		basic.setIdentityDocumentTypeName("身份证");
//		basic.setIdNumber(idCard);
//		basic.setSexId(sexId);
//		basic.setSexName(sexName);
//		basic.setBirthday(birthday);
//		String nationalityCode = map.get("NATIONALITYCODE")!=null ? map.get("NATIONALITYCODE").toString():null;
//		List<Map<String, Object>> nationalitys = new ArrayList<Map<String, Object>>();
//		Integer nationalityId = null;
//		String nationalityName = null;
//		if(outHospitalTypeCode!=null){
//			nationalitys = exportDataMapper.getMysqlNationalityByCode(nationalityCode);
//			if(!nationalitys.isEmpty()){
//				nationalityId = Integer.parseInt(nationalitys.get(0).get("id").toString());
//				nationalityName = nationalitys.get(0).get("name").toString();
//			}
//		}
//		basic.setNationalityId(nationalityId);
//		basic.setNationalityName(nationalityName);
//		
//		
//		String nationName = map.get("NATIONNAME")!=null ? map.get("NATIONNAME").toString():null;
//		List<Map<String, Object>> nations = new ArrayList<Map<String, Object>>();
//		Integer nationId = null;
//		if(nationName!=null){
//			nations = exportDataMapper.getMysqlNationByName(nationName);
//			if(!nations.isEmpty()){
//				nationId = Integer.parseInt(nations.get(0).get("id").toString());
//			}
//		}
//		basic.setNationId(nationId);
//		basic.setNationName(nationName);
//		
//		
//		String professionCode = map.get("PROFESSIONCODE")!=null ? map.get("PROFESSIONCODE").toString():null;
//		List<Map<String, Object>> professions = new ArrayList<Map<String, Object>>();
//		Integer professionId = null;
//		String professionName = null;
//		if(professionCode!=null){
//			professions = exportDataMapper.getMysqlProfessionByCode(professionCode);
//			if(!professions.isEmpty()){
//				professionId = Integer.parseInt(professions.get(0).get("id").toString());
//				professionName = professions.get(0).get("name").toString();
//			}
//		}
//		basic.setProfessionId(professionId);
//		basic.setProfessionName(professionName);
//		
//		String marriageName = map.get("MARRIAGENAME")!=null ? map.get("MARRIAGENAME").toString():null;
//		List<Map<String, Object>> marriages = new ArrayList<Map<String, Object>>();
//		Integer marriageId = null;
//		if(marriageName!=null){
//			marriages = exportDataMapper.getMysqlMarriageByName(marriageName);
//			if(!marriages.isEmpty()){
//				marriageId = Integer.parseInt(marriages.get(0).get("id").toString());
//			}
//		}
//		basic.setMarriageId(marriageId);
//		basic.setMarriageName(marriageName);
//		String familyAddress = map.get("FAMILYADDRESS")!=null ? map.get("FAMILYADDRESS").toString():null;
//		basic.setFamilyAddress(familyAddress);
//		
//		String familyPostCode = map.get("FAMILYPOSTCODE")!=null ? map.get("FAMILYPOSTCODE").toString():null;
//		basic.setFamilyPostCode(familyPostCode);
//		
//		String workUnit = map.get("WORKUNIT")!=null ? map.get("WORKUNIT").toString():null;
//		basic.setWorkUnit(workUnit);
//		
//		String linkManName = map.get("LINKMANNAME")!=null ? map.get("LINKMANNAME").toString():null;
//		basic.setLinkManName(linkManName);
//		
//		String linkManAddress = map.get("LINKMANADDRESS")!=null ? map.get("LINKMANADDRESS").toString():null;
//		basic.setLinkManAddress(linkManAddress);
//		
//		String relativeRelationCode = map.get("RELATIVERELATIONCODE")!=null ? map.get("RELATIVERELATIONCODE").toString():null;
//		List<Map<String, Object>> relativeRelations = new ArrayList<Map<String, Object>>();
//		Integer relativeRelationId = null;
//		String relativeRelationName = null;
//		if(relativeRelationCode!=null){
//			relativeRelations = exportDataMapper.getMysqlRelativeRelationByCode(relativeRelationCode);
//			if(!relativeRelations.isEmpty()){
//				relativeRelationId = Integer.parseInt(relativeRelations.get(0).get("id").toString());
//				relativeRelationName = relativeRelations.get(0).get("name").toString();
//			}
//		}
//		basic.setRelativeRelationId(relativeRelationId);
//		basic.setRelativeRelationName(relativeRelationName);
//		
//		String linkManPhone = map.get("LINKMANPHONE")!=null ? map.get("LINKMANPHONE").toString():null;
//		basic.setLinkManPhone(linkManPhone);
//		
//		String clinicalReceptionDateStr = map.get("CLINICALRECEPTIONDATE")!=null ? map.get("CLINICALRECEPTIONDATE").toString():null;
//		Date clinicalReceptionDate = null;
//		if(clinicalReceptionDateStr != null){
//			try {
//				clinicalReceptionDate = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,clinicalReceptionDateStr);
//			} catch (ParseException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//		}
//		basic.setClinicalReceptionDate(clinicalReceptionDate);
//		
//		String consultingDoctorName = map.get("CONSULTINGDOCTORNAME")!=null ? map.get("CONSULTINGDOCTORNAME").toString():null;
//		List<Map<String, Object>> consultingDoctors = new ArrayList<Map<String, Object>>();
//		Integer consultingDoctorId = null;
//		if(consultingDoctorName!=null){
//			consultingDoctors = exportDataMapper.getMysqlMedicalWorkerByName(consultingDoctorName);
//			if(!consultingDoctors.isEmpty()){
//				consultingDoctorId = Integer.parseInt(consultingDoctors.get(0).get("id").toString());
//			}
//		}
//		basic.setOutpatientOfDoctorId(consultingDoctorId);
//		basic.setOutpatientOfDoctorName(consultingDoctorName);
//		
//		
//		String responsiblePersonName = map.get("RESPONSIBLEPERSONNAME")!=null ? map.get("RESPONSIBLEPERSONNAME").toString():null;
//		List<Map<String, Object>> responsiblePersons = new ArrayList<Map<String, Object>>();
//		Integer responsiblePersonId = null;
//		if(responsiblePersonName!=null){
//			responsiblePersons = exportDataMapper.getMysqlMedicalWorkerByName(responsiblePersonName);
//			if(!responsiblePersons.isEmpty()){
//				responsiblePersonId = Integer.parseInt(responsiblePersons.get(0).get("id").toString());
//			}
//		}
//		basic.setResponsiblePersonId(responsiblePersonId);
//		basic.setResponsiblePersonName(responsiblePersonName);
//		
//		
//		String inHospitalTypeCode = map.get("INHOSPITALTYPECODE")!=null ? map.get("INHOSPITALTYPECODE").toString():null;
//		List<Map<String, Object>> inHospitalTypes = new ArrayList<Map<String, Object>>();
//		Integer inHospitalTypeId = null;
//		String inHospitalTypeName = null;
//		if(inHospitalTypeCode!=null){
//			inHospitalTypes = exportDataMapper.getMysqlInHospitalTypeByCode(inHospitalTypeCode);
//			if(!inHospitalTypes.isEmpty()){
//				inHospitalTypeId = Integer.parseInt(inHospitalTypes.get(0).get("id").toString());
//				inHospitalTypeName = inHospitalTypes.get(0).get("name").toString();
//			}
//		}
//		basic.setInHospitalTypeId(inHospitalTypeId);
//		basic.setInHospitalTypeName(inHospitalTypeName);
//		
//		String inHospitalStateCode = map.get("INHOSPITALTYPECODE")!=null ? map.get("INHOSPITALTYPECODE").toString():null;
//		List<Map<String, Object>> inHospitalStates = new ArrayList<Map<String, Object>>();
//		Integer inHospitalStateId = null;
//		String inHospitalStateName = null;
//		if(inHospitalStateCode!=null){
//			inHospitalStates = exportDataMapper.getMysqlInHospitalStateByCode(inHospitalStateCode);
//			if(!inHospitalStates.isEmpty()){
//				inHospitalStateId = Integer.parseInt(inHospitalStates.get(0).get("id").toString());
//				inHospitalStateName = inHospitalStates.get(0).get("name").toString();
//			}
//		}
//		basic.setInHospitalStateId(inHospitalStateId);
//		basic.setInHospitalStateName(inHospitalStateName);
//		basic.setInDeptId(inDeptId);
//		basic.setInDeptName(inDeptName);
//		basic.setOutDeptId(outDeptId);
//		basic.setOutDeptName(outDeptName);
//		basic.setInHospitalDate(inHospitalDate);
//		basic.setOutHospitalDate(outHospitalDate);
//		basic.setOutHospitalTypeId(outHospitalTypeId);
//		basic.setOutHospitalTypeName(outHospitalTypeName);
//		String autopsyStr = map.get("AUTOPSY")!=null ? map.get("AUTOPSY").toString():null;
//		if(autopsyStr != null){
//			if(autopsyStr.equals("1")){
//				basic.setAutopsy(true);
//			}else if(autopsyStr.equals("2")){
//				basic.setAutopsy(false);
//			}
//		}
//		
//		HospitalizationNurseRecordInfo nurseRecordInfo = new HospitalizationNurseRecordInfo();
//		nurseRecordInfo.setFirstGuid(firstLevelMedical.getGuid());
//		BigDecimal criticalOfDay = map.get("CRITICAL_COND_DAYS")!=null ? (BigDecimal)map.get("CRITICAL_COND_DAYS"):null;
//		nurseRecordInfo.setCriticalOfDay(criticalOfDay);
//		BigDecimal sickOfDay = map.get("SERIOUS_COND_DAYS")!=null ? (BigDecimal)map.get("SERIOUS_COND_DAYS"):null;
//		nurseRecordInfo.setSickOfDay(sickOfDay);
//		BigDecimal ICUNurseOfDay = map.get("ICU_DAYS")!=null ? (BigDecimal)map.get("ICU_DAYS"):null;
//		nurseRecordInfo.setICUNurseOfDay(ICUNurseOfDay);
//		BigDecimal CCUNurseOfDay = map.get("CCU_DAYS")!=null ? (BigDecimal)map.get("CCU_DAYS"):null;
//		nurseRecordInfo.setCCUNurseOfDay(CCUNurseOfDay);
//		BigDecimal specialNurseOfDay = map.get("SPEC_LEVEL_NURS_DAYS")!=null ? (BigDecimal)map.get("SPEC_LEVEL_NURS_DAYS"):null;
//		nurseRecordInfo.setSpecialNurseOfDay(specialNurseOfDay);
//		BigDecimal firstLevelNurseOfDay = map.get("FIRST_LEVEL_NURS_DAYS")!=null ? (BigDecimal)map.get("FIRST_LEVEL_NURS_DAYS"):null;
//		nurseRecordInfo.setFirstLevelNurseOfDay(firstLevelNurseOfDay);
//		BigDecimal secondLevelNurseOfDay = map.get("SECOND_LEVEL_NURS_DAYS")!=null ? (BigDecimal)map.get("SECOND_LEVEL_NURS_DAYS"):null;
//		nurseRecordInfo.setSecondLevelNurseOfDay(secondLevelNurseOfDay);
//		
//		
//		BloodTransfusionInfo bloodTransfusionInfo = new BloodTransfusionInfo();
//		bloodTransfusionInfo.setFirstGuid(firstLevelMedical.getGuid());
//		BigDecimal infusionBloodTimes = map.get("BLOOD_TRAN_TIMES")!=null ? (BigDecimal)map.get("BLOOD_TRAN_TIMES"):null;
//		bloodTransfusionInfo.setInfusionBloodTimes(infusionBloodTimes);
//		
//		BigDecimal infusionBloodTotalVolume = map.get("BLOOD_TRAN_VOL")!=null ? (BigDecimal)map.get("BLOOD_TRAN_VOL"):null;
//		bloodTransfusionInfo.setInfusionBloodTotalVolume(infusionBloodTotalVolume);
//		
//		BigDecimal infusionBloodReactTimes = map.get("BLOOD_TRAN_REACT_TIMES")!=null ? (BigDecimal)map.get("BLOOD_TRAN_REACT_TIMES"):null;
//		bloodTransfusionInfo.setInfusionBloodReactTimes(infusionBloodReactTimes);
//		
//		HospitalizationPressureSoreInfo pressureSoreInfo = new HospitalizationPressureSoreInfo();
//		pressureSoreInfo.setFirstGuid(firstLevelMedical.getGuid());
//		
//		BigDecimal pressureSoreTimes = map.get("DECUBITAL_ULCER_TIMES")!=null ? (BigDecimal)map.get("DECUBITAL_ULCER_TIMES"):null;
//		pressureSoreInfo.setPressureSoreTimes(pressureSoreTimes);
//		
//		HospitalizationCost hospitalizationCost = new HospitalizationCost();
//		BigDecimal totalCost = map.get("TOTAL_COSTS")!=null ? (BigDecimal)map.get("TOTAL_COSTS"):null;
//		BigDecimal actuallyCost = map.get("TOTAL_PAYMENTS")!=null ? (BigDecimal)map.get("TOTAL_PAYMENTS"):null;
//		hospitalizationCost.setTotalCost(totalCost);
//		hospitalizationCost.setActuallyCost(actuallyCost);
//		
//		HospitalizationCureInfo cureInfo = new HospitalizationCureInfo();
//		cureInfo.setFirstGuid(firstLevelMedical.getGuid());
//		BigDecimal rescueNumber = map.get("RESCUETIMES")!=null ? (BigDecimal)map.get("RESCUETIMES"):null;
//		BigDecimal rescueSucceedNumber = map.get("RESCUSUCCESSTIMES")!=null ? (BigDecimal)map.get("RESCUSUCCESSTIMES"):null;
//		if(rescueNumber != null){
//			cureInfo.setRescueNumber(rescueNumber.intValue());
//		}
//		if(rescueSucceedNumber != null){
//			cureInfo.setRescueSucceedNumber(rescueSucceedNumber.intValue());
//		}
//		
//		String bloodTypeName = map.get("BLOODTYPENAME")!=null ? map.get("BLOODTYPENAME").toString():null;
//		Integer bloodTypeId = null;
//		List<Map<String, Object>> bloodTypes = new ArrayList<Map<String, Object>>();
//		
//		if(bloodTypeName!=null){
//			bloodTypes = exportDataMapper.getMysqlBloodTypeByName(bloodTypeName);
//			if(!bloodTypes.isEmpty()){
//				bloodTypeId = Integer.parseInt(bloodTypes.get(0).get("id").toString());
//			}
//		}
//		cureInfo.setBloodTypeId(bloodTypeId);
//		cureInfo.setBloodTypeName(bloodTypeName);
//		
//		String rhBloodTypeName = map.get("RHBLOODTYPENAME")!=null ? map.get("RHBLOODTYPENAME").toString():null;
//		Integer rhBloodTypeId = null;
//		List<Map<String, Object>> rhBloodTypes = new ArrayList<Map<String, Object>>();
//		
//		if(rhBloodTypeName!=null){
//			rhBloodTypes = exportDataMapper.getMysqlRhBloodTypeByName(rhBloodTypeName);
//			if(!rhBloodTypes.isEmpty()){
//				rhBloodTypeId = Integer.parseInt(rhBloodTypes.get(0).get("id").toString());
//			}
//		}
//		cureInfo.setRhBloodTypeId(rhBloodTypeId);
//		cureInfo.setRhBloodTypeName(rhBloodTypeName);
//		BigDecimal infusionReactTimes = map.get("INFUSIONREACTTIMES")!=null ? (BigDecimal)map.get("INFUSIONREACTTIMES"):null;
//		if(infusionReactTimes != null){
//			cureInfo.setInfusionReactTimes(infusionReactTimes.intValue());
//		}
//		BigDecimal followUpClinic = map.get("FOLLOWINDICATOR")!=null ? (BigDecimal)map.get("FOLLOWINDICATOR"):null;
//		if(followUpClinic != null){
//			if(followUpClinic.intValue() ==0){
//				cureInfo.setFollowUpClinicLimit(false);
//			}else if(followUpClinic.intValue() ==1){
//				cureInfo.setFollowUpClinicLimit(true);
//			}
//		}
//		BigDecimal followInterval = map.get("FOLLOWINTERVAL")!=null ? (BigDecimal)map.get("FOLLOWINTERVAL"):null;
//		if(followInterval != null){
//			cureInfo.setFollowUpClinicNumberOfDays(followInterval);
//		}
//		
//		
//		String directorName = map.get("DIRECTOR")!=null ? map.get("DIRECTOR").toString():null;
//		List<Map<String, Object>> directors = new ArrayList<Map<String, Object>>();
//		Integer directorId = null;
//		if(directorName!=null){
//			directors = exportDataMapper.getMysqlMedicalWorkerByName(directorName);
//			if(!directors.isEmpty()){
//				directorId = Integer.parseInt(directors.get(0).get("id").toString());
//			}
//		}
//		cureInfo.setHeadOfDepartmentId(directorId);
//		cureInfo.setHeadOfDepartmentName(directorName);
//		
//		
//		String attendingOfDoctorName = map.get("ATTENDING_DOCTOR")!=null ? map.get("ATTENDING_DOCTOR").toString():null;
//		List<Map<String, Object>> attendingOfDoctors = new ArrayList<Map<String, Object>>();
//		Integer attendingOfDoctorId = null;
//		if(attendingOfDoctorName!=null){
//			attendingOfDoctors = exportDataMapper.getMysqlMedicalWorkerByName(attendingOfDoctorName);
//			if(!attendingOfDoctors.isEmpty()){
//				attendingOfDoctorId = Integer.parseInt(attendingOfDoctors.get(0).get("id").toString());
//			}
//		}
//		cureInfo.setAttendingOfDoctorId(attendingOfDoctorId);
//		cureInfo.setAttendingOfDoctorName(attendingOfDoctorName);
//		
//		String residentOfDoctorName = map.get("DOCTOR_IN_CHARGE")!=null ? map.get("DOCTOR_IN_CHARGE").toString():null;
//		List<Map<String, Object>> residentOfDoctors = new ArrayList<Map<String, Object>>();
//		Integer residentOfDoctorId = null;
//		if(residentOfDoctorName!=null){
//			residentOfDoctors = exportDataMapper.getMysqlMedicalWorkerByName(residentOfDoctorName);
//			if(!residentOfDoctors.isEmpty()){
//				residentOfDoctorId = Integer.parseInt(residentOfDoctors.get(0).get("id").toString());
//			}
//		}
//		cureInfo.setResidentOfDoctorId(residentOfDoctorId);
//		cureInfo.setResidentOfDoctorName(residentOfDoctorName);
//		
//		
//		String medicalOfCoderName = map.get("CATALOGER")!=null ? map.get("CATALOGER").toString():null;
//		List<Map<String, Object>> medicalOfCoders = new ArrayList<Map<String, Object>>();
//		Integer medicalOfCoderId = null;
//		if(medicalOfCoderName!=null){
//			medicalOfCoders = exportDataMapper.getMysqlMedicalWorkerByName(medicalOfCoderName);
//			if(!medicalOfCoders.isEmpty()){
//				medicalOfCoderId = Integer.parseInt(medicalOfCoders.get(0).get("id").toString());
//			}
//		}
//		cureInfo.setMedicalOfCoderId(medicalOfCoderId);
//		cureInfo.setMedicalOfCoderName(medicalOfCoderName);
//		
//		List<Map<String, Object>> diagComparingRecords = (List<Map<String, Object>>)data.get("diagComparingRecords");
//		for (Map<String, Object> diagComparingRecord : diagComparingRecords) {
//			String diagGroupName = diagComparingRecord.get("DIAG_COMP_GROUP_NAME")!=null ? diagComparingRecord.get("DIAG_COMP_GROUP_NAME").toString():null;
//			
//			String diagCorrCode = diagComparingRecord.get("DIAG_CORRESPONDENCE")!=null ? diagComparingRecord.get("DIAG_CORRESPONDENCE").toString():null;
//			String diagCorrName = null;
//			if(diagCorrCode != null){
//				List<Map<String, Object>> diagCorrs = exportDataMapper.getMysqlDiagCoincidenceTypeByCode(diagCorrCode);
//				if(!diagCorrs.isEmpty()){
//					diagCorrName = (String)diagCorrs.get(0).get("name");
//				}
//			}
//			if("门诊与出院".equalsIgnoreCase(diagGroupName)){
//				cureInfo.setOutpatientAndDischargeDiagCode(diagCorrCode);
//				cureInfo.setOutpatientAndDischargeDiagName(diagCorrName);
//			}else if("入院与出院".equalsIgnoreCase(diagGroupName)){
//				cureInfo.setOutpatientAndInpatientDiagCode(diagCorrCode);
//				cureInfo.setOutpatientAndInpatientDiagName(diagCorrName);
//			}else if("术前与术后".equalsIgnoreCase(diagGroupName)){
//				cureInfo.setBeforeOpsAndAfterOpsDiagCode(diagCorrCode);
//				cureInfo.setBeforeOpsAndAfterOpsDiagName(diagCorrName);
//			}else if("临床与病理".equalsIgnoreCase(diagGroupName)){
//				cureInfo.setClinicalAndPathologDiagCode(diagCorrCode);
//				cureInfo.setClinicalAndPathologDiagName(diagCorrName);
//			}else if("放射与病理".equalsIgnoreCase(diagGroupName)){
//				cureInfo.setRadiologAndPathologDiagCode(diagCorrCode);
//				cureInfo.setRadiologAndPathologDiagName(diagCorrName);
//			}
//		}
//		
//		List<Map<String, Object>> diagnosisRecords = (List<Map<String, Object>>)data.get("diagnosisRecords");
//		HospitalizationDiagnosisInfo diagnosisInfo = new HospitalizationDiagnosisInfo();
//		diagnosisInfo.setFirstGuid(firstLevelMedical.getGuid());
//		for (Map<String, Object> diagnosisRecord : diagnosisRecords) {
//			HospitalizationDiagnosis diagnosis = new HospitalizationDiagnosis();
//			String diagnoseTypeCode = diagnosisRecord.get("DIAGNOSIS_TYPE")!=null ? diagnosisRecord.get("DIAGNOSIS_TYPE").toString():null;
//			List<Map<String, Object>> diagnoseTypes = new ArrayList<Map<String, Object>>();
//			Integer diagnoseTypeId = null;
//			String diagnoseTypeName = null;
//			if(diagnoseTypeCode!=null){
//				diagnoseTypes = exportDataMapper.getMysqlDiagnoseTypeByCode(diagnoseTypeCode);
//				if(!diagnoseTypes.isEmpty()){
//					diagnoseTypeId = Integer.parseInt(diagnoseTypes.get(0).get("id").toString());
//					diagnoseTypeName = diagnoseTypes.get(0).get("name").toString();
//				}
//			}
//			diagnosis.setDiagnoseTypeId(diagnoseTypeId);
//			diagnosis.setDiagnoseTypeName(diagnoseTypeName);
//			
//			
//			String diseaseName = diagnosisRecord.get("DIAGNOSIS_DESC")!=null ? diagnosisRecord.get("DIAGNOSIS_DESC").toString():null;
//			List<Map<String, Object>> diseases = new ArrayList<Map<String, Object>>();
//			String diseaseCode = null;
//			if(diseaseName!=null){
//				diseases = exportDataMapper.getMysqlDiseaseByName(diseaseName);
//				if(!diseases.isEmpty()){
//					diseaseCode = diseases.get(0).get("code").toString();
//					
//				}
//			}
//			diagnosis.setDiseaseCode(diseaseCode);
//			diagnosis.setDiseaseName(diseaseName);
//			
//			String treatmentResultName = diagnosisRecord.get("TREAT_RESULT")!=null ? diagnosisRecord.get("TREAT_RESULT").toString():null;
//			List<Map<String, Object>> treatmentResults = new ArrayList<Map<String, Object>>();
//			Integer treatmentResultId = null;
//			if(treatmentResultName!=null){
//				treatmentResults = exportDataMapper.getMysqlTreatmentResultByName(treatmentResultName);
//				if(!treatmentResults.isEmpty()){
//					treatmentResultId = Integer.parseInt(treatmentResults.get(0).get("id").toString());
//					
//				}
//			}
//			diagnosis.setTreatmentResultId(treatmentResultId);
//			diagnosis.setTreatmentResultName(treatmentResultName);
//			
//			String confirmedDateStr = diagnosisRecord.get("DIAGNOSIS_DATE")!=null ? diagnosisRecord.get("DIAGNOSIS_DATE").toString():null;
//			Date confirmedDate = null;
//			if(confirmedDateStr != null){
//				try {
//					confirmedDate = DateUtil.dateParse(DateUtil.DATE_FORMATE,confirmedDateStr);
//				} catch (ParseException e) {
//					// TODO Auto-generated catch block
//					e.printStackTrace();
//				}
//			}
//			diagnosis.setConfirmedDate(confirmedDate);
//			BigDecimal diagnoseSort = diagnosisRecord.get("DIAGNOSIS_NO")!=null ? (BigDecimal)diagnosisRecord.get("DIAGNOSIS_NO"):null;
//			if(diagnoseSort != null){
//				diagnosis.setDiagnoseSort(diagnoseSort.intValue());
//			}
//			diagnosisInfo.getHospitalizationDiagnosis().add(diagnosis);
//		}
//		
//		List<Map<String, Object>> operationRecords = (List<Map<String, Object>>)data.get("operationRecords");
//		HospitalizationOperationInfo operationInfo = new HospitalizationOperationInfo();
//		operationInfo.setFirstGuid(firstLevelMedical.getGuid());
//		for (Map<String, Object> operationRecord : operationRecords) {
//			HospitalizationOperation operation = new HospitalizationOperation();
//			String operationCode = operationRecord.get("OPERATION_CODE")!=null ? operationRecord.get("OPERATION_CODE").toString():null;
//			String operationName = operationRecord.get("OPERATION_DESC")!=null ? operationRecord.get("OPERATION_DESC").toString():null;
//			operation.setOperationCode(operationCode);
//			operation.setOperationName(operationName);
//			String incisionLevelName = operationRecord.get("WOUND_GRADE")!=null ? operationRecord.get("WOUND_GRADE").toString():null;
//			List<Map<String, Object>> incisionLevels =new ArrayList<Map<String,Object>>();
//			Integer incisionLevelId = null;
//			if(incisionLevelName != null){
//				incisionLevels = exportDataMapper.getMysqlIncisionLevelByName(incisionLevelName);
//				if(!incisionLevels.isEmpty()){
//					incisionLevelId = Integer.parseInt(incisionLevels.get(0).get("id").toString());
//				}
//			}
//			operation.setIncisionLevelId(incisionLevelId);
//			operation.setIncisionLevelName(incisionLevelName);
//			
//			String cicatrizationTypeName = operationRecord.get("HEAL")!=null ? operationRecord.get("HEAL").toString():null;
//			List<Map<String, Object>> cicatrizationTypes =new ArrayList<Map<String,Object>>();
//			Integer cicatrizationTypeId = null;
//			if(cicatrizationTypeName != null){
//				cicatrizationTypes = exportDataMapper.getMysqlCicatrizationTypeByName(cicatrizationTypeName);
//				if(!cicatrizationTypes.isEmpty()){
//					cicatrizationTypeId = Integer.parseInt(cicatrizationTypes.get(0).get("id").toString());
//				}
//			}
//			operation.setCicatrizationTypeId(cicatrizationTypeId);
//			operation.setCicatrizationTypeName(cicatrizationTypeName);
//			String operationStartDateStr = operationRecord.get("OPERATING_DATE")!=null ? operationRecord.get("OPERATING_DATE").toString():null;
//			
//			Date operationStartDate = null;
//			if(operationStartDateStr != null){
//				try {
//					operationStartDate = DateUtil.dateParse(DateUtil.DATE_FORMATE,operationStartDateStr);
//				} catch (ParseException e) {
//					// TODO Auto-generated catch block
//					e.printStackTrace();
//				}
//			}
//			operation.setOperationStartDate(operationStartDate);
//			operation.setOperationEndDate(operationStartDate);
//			
//			String anaesthesiaTypeName = operationRecord.get("ANAESTHESIA_METHOD")!=null ? operationRecord.get("ANAESTHESIA_METHOD").toString():null;
//			List<Map<String, Object>> anaesthesiaTypes =new ArrayList<Map<String,Object>>();
//			Integer anaesthesiaTypeId = null;
//			if(anaesthesiaTypeName != null){
//				anaesthesiaTypes = exportDataMapper.getMysqlAnaesthesiaWayByName(anaesthesiaTypeName);
//				if(!anaesthesiaTypes.isEmpty()){
//					anaesthesiaTypeId = Integer.parseInt(anaesthesiaTypes.get(0).get("id").toString());
//				}
//			}
//			operation.setAnaesthesiaTypeId(anaesthesiaTypeId);
//			operation.setAnaesthesiaTypeName(anaesthesiaTypeName);
//			
//			
//			String surgeryOfDoctorName = operationRecord.get("OPERATOR")!=null ? operationRecord.get("OPERATOR").toString():null;
//			List<Map<String, Object>> surgeryOfDoctors =new ArrayList<Map<String,Object>>();
//			Integer surgeryOfDoctorId = null;
//			if(surgeryOfDoctorName != null){
//				surgeryOfDoctors = exportDataMapper.getMysqlMedicalWorkerByName(surgeryOfDoctorName);
//				if(!surgeryOfDoctors.isEmpty()){
//					surgeryOfDoctorId = Integer.parseInt(surgeryOfDoctors.get(0).get("id").toString());
//				}
//			}
//			operation.setSurgeryOfDoctorName(surgeryOfDoctorName);
//			operation.setSurgeryOfDoctorId(surgeryOfDoctorId);
//			
//			String firstOpsAssistantName = operationRecord.get("FIRST_ASSISTANT")!=null ? operationRecord.get("FIRST_ASSISTANT").toString():null;
//			List<Map<String, Object>> firstOpsAssistants =new ArrayList<Map<String,Object>>();
//			Integer firstOpsAssistantId = null;
//			if(firstOpsAssistantName != null){
//				firstOpsAssistants = exportDataMapper.getMysqlMedicalWorkerByName(firstOpsAssistantName);
//				if(!firstOpsAssistants.isEmpty()){
//					firstOpsAssistantId = Integer.parseInt(firstOpsAssistants.get(0).get("id").toString());
//				}
//			}
//			operation.setFirstOpsAssistantId(firstOpsAssistantId);
//			operation.setFirstOpsAssistantName(firstOpsAssistantName);
//			
//			String secondOpsAssistantName = operationRecord.get("SECOND_ASSISTANT")!=null ? operationRecord.get("SECOND_ASSISTANT").toString():null;
//			List<Map<String, Object>> secondOpsAssistants =new ArrayList<Map<String,Object>>();
//			Integer secondOpsAssistantId = null;
//			if(secondOpsAssistantName != null){
//				secondOpsAssistants = exportDataMapper.getMysqlMedicalWorkerByName(secondOpsAssistantName);
//				if(!secondOpsAssistants.isEmpty()){
//					secondOpsAssistantId = Integer.parseInt(secondOpsAssistants.get(0).get("id").toString());
//				}
//			}
//			operation.setSecondOpsAssistantId(secondOpsAssistantId);
//			operation.setSecondOpsAssistantName(secondOpsAssistantName);
//			
//			String anaesthesiaOfDoctorName = operationRecord.get("ANESTHESIA_DOCTOR")!=null ? operationRecord.get("ANESTHESIA_DOCTOR").toString():null;
//			List<Map<String, Object>> anaesthesiaOfDoctors =new ArrayList<Map<String,Object>>();
//			Integer anaesthesiaOfDoctorId = null;
//			if(anaesthesiaOfDoctorName != null){
//				anaesthesiaOfDoctors = exportDataMapper.getMysqlMedicalWorkerByName(anaesthesiaOfDoctorName);
//				if(!anaesthesiaOfDoctors.isEmpty()){
//					anaesthesiaOfDoctorId = Integer.parseInt(anaesthesiaOfDoctors.get(0).get("id").toString());
//				}
//			}
//			operation.setAnaesthesiaOfDoctorId(anaesthesiaOfDoctorId);
//			operation.setAnaesthesiaOfDoctorName(anaesthesiaOfDoctorName);
//			operationInfo.getOperations().add(operation);
//		}
//		
//		HospitalizationChangeOfficeInfo changeOfficeInfo = new HospitalizationChangeOfficeInfo();
//		changeOfficeInfo.setFirstGuid(firstLevelMedical.getGuid());
//		List<Map<String, Object>> changeOfficeRecords = (List<Map<String, Object>>)data.get("changeOfficeRecords");
//		for (Map<String, Object> changeOfficeRecord : changeOfficeRecords) {
//			HospitalizationChangeOffice changeOffice = new HospitalizationChangeOffice();
//			String outOfficeCode = changeOfficeRecord.get("DEPT_STAYED")!=null ? changeOfficeRecord.get("DEPT_STAYED").toString():null;
//			List<Map<String, Object>> outOffices =new ArrayList<Map<String,Object>>();
//			Integer outOfficeId = null;
//			String outOfficeName = null;
//			if(outDeptCode != null){
//				outOffices = exportDataMapper.getOfficesByOfficeCode(outOfficeCode);
//				if(!outOffices.isEmpty()){
//					outOfficeId = Integer.parseInt(outOffices.get(0).get("id").toString());
//					outOfficeName = (String)outOffices.get(0).get("name");
//				}
//			}
//			changeOffice.setOutOfficeId(outOfficeId);
//			changeOffice.setOutOfficeName(outOfficeName);
//			
//			String inOfficeCode = changeOfficeRecord.get("DEPT_TRANSFERED_TO")!=null ? changeOfficeRecord.get("DEPT_TRANSFERED_TO").toString():null;
//			List<Map<String, Object>> inOffices =new ArrayList<Map<String,Object>>();
//			Integer inOfficeId = null;
//			String inOfficeName = null;
//			if(inDeptCode != null){
//				inOffices = exportDataMapper.getOfficesByOfficeCode(inOfficeCode);
//				if(!inOffices.isEmpty()){
//					inOfficeId = Integer.parseInt(inOffices.get(0).get("id").toString());
//					inOfficeName = (String)inOffices.get(0).get("name");
//				}
//			}
//			changeOffice.setInOfficeId(inOfficeId);
//			changeOffice.setInOfficeName(inOfficeName);
//			
//			String changeOfficeDateStr = changeOfficeRecord.get("DISCHARGE_DATE_TIME")!=null ? changeOfficeRecord.get("DISCHARGE_DATE_TIME").toString():null;
//			
//			Date changeOfficeDate = null;
//			if(changeOfficeDateStr != null){
//				try {
//					changeOfficeDate = DateUtil.dateParse(DateUtil.DATE_FORMATE,changeOfficeDateStr);
//				} catch (ParseException e) {
//					// TODO Auto-generated catch block
//					e.printStackTrace();
//				}
//			}
//			changeOffice.setChangeOfficeDate(changeOfficeDate);
//			changeOfficeInfo.getHospitalizationChangeOffices().add(changeOffice);
//		}
//		String filePath = "D:/publics/hospitalization_note/";
//		String fileName = basic.getFirstGuid() + ".txt";
//		try {
//			//查询是否已存在一次住院信息
//			String jsonStr =null;
//			//根据firstGuid查询住院基本信息
//			String hosBasicJson=hospNoteBasicJsonService.getHospBasicJsonByFirstGuid(StringUtil.handleJsonParam(basic.getFirstGuid()));
//			Map<String, Object> jsonMap =this.getHospBasicJson(hosBasicJson);
//			if(jsonMap!=null && jsonMap.size()>0){
//				
//				jsonMap.put("hospitalizationNoteBasic", basic);
//				jsonMap.put("hospitalizationCureInfo", cureInfo);
//				jsonMap.put("hospitalizationDiagnosisInfo", diagnosisInfo);
//				jsonMap.put("operationInfo", operationInfo);
//				jsonMap.put("hospitalChangeOfficeInfo", changeOfficeInfo);
//				jsonMap.put("hospitalizationNurseRecordInfo", nurseRecordInfo);
//				jsonMap.put("bloodTransfusionInfo", bloodTransfusionInfo);
//				jsonMap.put("hospitalizationPressureSoreInfo", pressureSoreInfo);
//				
//				jsonMap.put("hospitalizationCost", hospitalizationCost);
//				
//				jsonStr = JsonUtils.objectToJson(jsonMap);
//				hospNoteBasicJsonService.updateHospBasicJsonByFirstGuid(basic.getFirstGuid(), jsonStr);
//				
//			}else{
//				jsonMap.put("hospitalizationNoteBasic", basic);
//				jsonMap.put("hospitalizationCureInfo", cureInfo);
//				jsonMap.put("hospitalizationDiagnosisInfo", diagnosisInfo);
//				jsonMap.put("operationInfo", operationInfo);
//				jsonMap.put("hospitalChangeOfficeInfo", changeOfficeInfo);
//				jsonMap.put("hospitalizationNurseRecordInfo", nurseRecordInfo);
//				jsonMap.put("bloodTransfusionInfo", bloodTransfusionInfo);
//				jsonMap.put("hospitalizationPressureSoreInfo", pressureSoreInfo);
//				
//				jsonMap.put("hospitalizationCost", hospitalizationCost);
//				jsonMap.put("firstGuid", basic.getFirstGuid());
//				jsonStr = JsonUtils.objectToJson(jsonMap);
//				hospNoteBasicJsonService.addHospNoteBasicJson(jsonStr);
//			}
//			CreateFileUtil.createFile(jsonStr, filePath, fileName);
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//		return 0;
//	}
//	
//	@TargetDataSource(name="ds1")
//	@Transactional
//	@Override
//	public int insertMysqlMedicalHospitalRecord(List<Map<String, Object>> datas){
//		
//		for (Map<String, Object> data : datas) {
//			insertMysqlMedicalHospitalRecord(data);
//		}
//		
//		
//		return 0;
//	}
	
	public Map<String,Object> getHospBasicJson(String json){
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		try {
			if(StringUtil.isNotEmpty(json)){
				jsonMap=JsonUtils.jsonToPojo(json, Map.class);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return jsonMap;
		
	}
	
	@Override
	public void exportMedicalHospitalRecord() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public int insertMysqlMedicalHospitalRecord(List<Map<String, Object>> medicalRecords) {
		// TODO Auto-generated method stub
		return 0;
	}
}
